﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace November {
    class FitToWidthViewMode : IViewMode {
        public Size UpdateLayout(Size container, Size content) {
            if (content.Height <= container.Height) {
                return container;
            }
            else {
                if (content.Width <= container.Width - SystemInformation.VerticalScrollBarWidth) {
                    return new Size(container.Width - SystemInformation.VerticalScrollBarWidth, content.Height);
                }
                else {
                    Int32 temp = (container.Width - SystemInformation.VerticalScrollBarWidth) * content.Height / content.Width;
                    if (temp <= container.Height) {
                        return container;
                    }
                    else {
                        return new Size(container.Width - SystemInformation.VerticalScrollBarWidth, temp);
                    }
                }
            }
        }
    }
}
